﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using compshop.Infrastructure.CompShopDataService;
using compshop.Modules.ListOfSuppliers.Presenter;

namespace compshop.Modules.ListOfSuppliers.View
{
    /// <summary>
    /// Логика взаимодействия для EmployeeListView.xaml
    /// </summary>
    public partial class SuppliersListView : UserControl, IViewSuppliersList
    {

        public SuppliersListView()
        {
            InitializeComponent();
            btnAdd.Click += new RoutedEventHandler(btnAdd_Click);
            btnEdit.Click += new RoutedEventHandler(btnEdit_Click);
        }
        public SuppliersListView(SuppliersListPresenter presenter)
            : this()
        {
            Presenter = presenter;
            Presenter.View = this;
        }
        void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            Presenter.EditSupplier(lvSuppliers.SelectedItem as Supplier);
        }
        
        void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            Presenter.AddSupplier();
            lvSuppliers.Items.Refresh();
        }

        public SuppliersListPresenter Presenter
        {
            get { return DataContext as SuppliersListPresenter; }
            set { DataContext = value; }
        }
    }
}
